<?php

/**
 * 前台 导航分类 模块 Model
 * ============================================================================
 * TBlog TBlog博客系统　BY Tmac PHP MVC framework
 * $Author: zhangwentao $  <zwttmac@qq.com>
 * $Id: category.class.php 1605 2011-03-15 08:16:23Z zhangwentao $
 * http://www.t-mac.org；
 */
class category extends Model
{

    private $links_table;
    private $category_table;

    /**
     * 初始化变量　定义私有变量
     */
    public function _init()
    {
        //连接数据库
        $this->connect();
        $this->links_table = '#@__links';
        $this->category_table = '#@__categories';
    }

    /**
     * 根据cat_id取cat_info
     * @param <type> $cat_id
     * @return <type>
     */
    public function getCatInfo($cat_id)
    {
        $sql = "SELECT cat_name FROM $this->category_table WHERE cat_id = $cat_id";
        $rs = $this->db->cacheGetRow($sql, 86400);
        $this->assign('cat_info', $rs);
        return $rs;
    }

    /**
     * 取链接
     * @param <type> $type
     * @param <type> $name
     * @param <type> $limit
     * @return <type>
     */
    public function getAlllink($cat_id, $name = 'alllink')
    {
        $time = time();

        $sql = "SELECT cat_id, link_url, link_name, link_target FROM $this->links_table ";
        $sql .= "WHERE IF(link_state_radio = 1, link_starttime<$time AND link_endtime>$time, link_state_radio <> 3) ";
        $sql .= "AND cat_id = $cat_id ";
        $sql .= "ORDER BY link_order DESC";

        $rs = $this->db->cacheGetAll($sql, 86400);

        $this->assign($name, $rs);
        return $rs;
    }

}